How to add "SKIP TO MAIN CONTENT" to websites 您所在的位置:网站首页 How To Create A Skip To Content Link CSS How to add "SKIP TO MAIN CONTENT" to websites

How to add "SKIP TO MAIN CONTENT" to websites

2024-07-13 13:02| 来源: 网络整理| 查看: 265

As part of this blog post let's see what is web accessibility, and how to add "skip to main content" link for web pages and why?.

Accessibility

As per w3.org

Web accessibility means that websites, tools, and technologies are designed and developed so that people with disabilities can use them. More specifically, people can: perceive, understand, navigate, and interact with the Web contribute to the Web

For a normal user when he visits a page, he/she directly jumps to the section of the page where they want to read. But if we consider visually impaired users or someone who uses screen reader, the assistive device has to read through the entire page before they can reach a point which interests them.

Let's assume when a user lands on the page , the screen reader will read the entire navigation/header and then goes to the actual content of the page. The user reads through the first page of your website once, now he/she goes to the second page and the screen reader will again start reading the entire navigation for them before they can go to the main content. This is where "SKIP TO MAIN CONTENT" link comes in handy for them.

How to add "SKIP TO MAIN CONTENT" on the page HTML Inside the body tag add an anchor tag as the first element. Add an id to the content you want the screenreader to jump/skip to. eg: 'main-content' Add the same id as the href value to the anchor tag eg: 'main-content' SKIP TO MAIN CONTENT ..... Main Body Content ..... ...... Enter fullscreen mode Exit fullscreen mode CSS Add CSS to the link to hide it from view. [P.S Do not use display:none or visibility hidden because screen readers will not read the element. Our main focus is for the screen reader to read the link] When the screenreader focuses on that element, make the element visible and also the screen reader will read the content inside the anchor tag . i.e "SKIP TO MAIN CONTENT" in our example. .skip-link { position: absolute; left: -999px; width: 1px; height: 1px; top: auto; } .skip-link:active, .skip-link:focus { color: #000; display: inline-block; height: auto; width: auto; position: static; margin: auto } Enter fullscreen mode Exit fullscreen mode References Accessibility Checkout my other blog posts Getting Started with JavaScript - Ultimate Free Resources 10 Things you can do in Chrome Developer Tools 2 Simple ways you can truncate text using CSS

Please share your feedbacks and suggestions in the comments below.

Lets connect on Twitter | LinkedIn for more web development related tips & tricks.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有